<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>入库</title>
	
	<link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
	<script src="js/jquery.min.js?v=2.1.4"></script>
</head>

<body>
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
            <div class="col-sm-6">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>编辑入库信息</h5>
						</div>
						<div class="ibox-content">
							<form class="form-horizontal m-t" id="commentForm" onSubmit="return uploadForm();">
								<div class="form-group">
									<label class="col-sm-3 control-label">款式内部编号：</label>
									<div class="col-sm-8">
										<input id="numstr" name="numstr" minlength="2" type="text" class="form-control" required="" aria-required="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">数量：</label>
									<div class="col-sm-8">
										<input id="number" name="number" minlength="1" type="text" class="form-control" required="number" aria-required="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">出厂价：</label>
									<div class="col-sm-8">
										<input id="radeprice" name="radeprice" minlength="1" type="text" class="form-control" required="number" aria-required="true">
									</div>
								</div>
								<div class="form-group">
                                 <label class="col-sm-3 control-label">入库时间：</label>
									<div class="col-sm-8">
										<input id="intotime" name="intotime" minlength="1" type="date" required>
									</div> 
                                      
                                </div>
								<div class="form-group">
									<label class="col-sm-3 control-label">注意：</label>
									<div class="col-sm-8">
										<label style="color: #F70C10">如有更改
											<span style="font-size: 25px">数量</span>,成功后请前往
											<span style="font-size: 25px">"现库存"</span>页面手动更改相关数据</label>
									</div>
								</div>
								
							
								
                       
        
        
    								
								
<!--
								<div class="form-group">
									<label class="col-sm-3 control-label">说明：</label>
									<div class="col-sm-8">
										<textarea id="ccomment" name="comment" class="form-control" required="" aria-required="true"></textarea>
									</div>
								</div>
-->
								<div class="form-group">
									<div class="col-sm-4 col-sm-offset-3">
										<button class="btn btn-primary" type="submit">提交</button>
										<button class="btn btn-primary" type="button" onclick="javascript:history.back(-1);">返回</button>
									</div>
								</div>
							</form>
							
						</div>
					</div>
              
            </div>
		</div>	
	</div>
	<script>
		//页面回显
		 $(document).ready(function (){
			 var key = window.location.href.split("?")[1].split("=")[0];
			var value = window.location.href.split("?")[1].split("=")[1];
			 if(key==="id"){
				var warehousingVO={
				id: value
				}
			}else{
				var warehousingVO={
				numstr:value
				}
			}
			console.log(warehousingVO);
			 
			 $.ajax({
            	//几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "http://localhost:8081/lecture/selectWarehousing" ,//url
                data: JSON.stringify(warehousingVO),
				contentType: "application/json;charset=UTF-8",
                success: function (rsp) {
                   	console.log(rsp);
					if(rsp.respCode==="0"){
						console.log(rsp.data);
					
						$("#numstr").val(rsp.data.numstr);
						$("#number").val(rsp.data.number);
						$("#radeprice").val(rsp.data.radeprice);
						//时间戳转换
						var newDate=new Date(rsp.data.intotime).Format('yyyy-MM-dd');
						console.log(newDate);
						$("#intotime").val(newDate);
					}else{
						alert(rsp.respDesc);
					}
					
					
				},
				error:function(){
					 window.location.href="500.html";
				}
            });
			 
			 
		 });
		
		//date 数据回显
		Date.prototype.Format = function (fmt) {
			var o = {
				"M+": this.getMonth() + 1, //月份 
				"d+": this.getDate(), //日 
				"h+": this.getHours(), //小时 
				"m+": this.getMinutes(), //分 
				"s+": this.getSeconds(), //秒 
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
				"S": this.getMilliseconds() //毫秒 
			};
			if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
			for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			return fmt;
		};
		
		
		//form 提交
		function uploadForm(){
			var id = window.location.href.split("?")[1].split("=")[1];
			console.log(id);
			var warehousingVO={
				id:id,
				numstr:$("#numstr").val(),
				number:$("#number").val(),
				radeprice:$("#radeprice").val(),
				intotime:$("#intotime").val()
			};
			console.log(warehousingVO);
			$.ajax({
            //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "http://localhost:8081/lecture/updateWarehousing" ,//url
                data: JSON.stringify(warehousingVO),
				contentType: "application/json;charset=UTF-8",
                success: function (rsp) {
                   	console.log(rsp);
					if(rsp.respCode==="0"){
						alert("修改成功");
						window.location.href="tableRK.html";
						
					}else{
						alert(rsp.respDesc);
						
					}
					
					
				},
				error:function(){
					 window.location.href="500.html";
					
				}
            });
			return false;
		}
	</script>
</body>
</html>
